<template>
  <div class="app-container">
    <!--表格数据列表-->
    <el-table :data="responseData.tableList"
                         border style="width: 100%;"
                         v-loading="pageData.loading"
                         element-loading-text="拼命加载中"
                         element-loading-spinner="el-icon-loading"
                         element-loading-background="rgba(0, 0, 0, 0.8)"
                         :header-cell-style="{ background: '#545C64', color: '#ffffff' }"
                         @selection-change="handleTableSelection">
    <el-table-column type="selection" width="55" align="center"/>
    <el-table-column fixed="left" prop="signId" label="规则ID" width="280" align="center"/>
    <el-table-column prop="signDay" label="连签天数" width="160" align="center">
      <template slot-scope="scope">
        <span><el-tag type="primary">第 [ <span>{{scope.row.signDay}}</span> ] 天</el-tag></span>
      </template>
    </el-table-column>
    <el-table-column prop="signIntegral" label="赠送积分" width="160" align="center">
      <template slot-scope="scope">
        <span><el-tag type="success">赠送 [ <span>{{scope.row.signIntegral}}</span> ] 积分值</el-tag></span>
      </template>
    </el-table-column>
    <el-table-column prop="signExpert" label="赠送经验" width="160" align="center">
      <template slot-scope="scope">
        <span><el-tag type="danger">赠送 [ <span>{{scope.row.signExpert}}</span> ] 经验值</el-tag></span>
      </template>
    </el-table-column>
    <el-table-column prop="signIsHaveLottery" label="额外奖励" width="160" align="center">
      <template slot-scope="scope">
        <span v-if="scope.row.signIsHaveLottery === 1"><el-tag type="primary">额外奖励</el-tag></span>
        <span v-if="scope.row.signIsHaveLottery === 0"><el-tag type="info">无额外奖励</el-tag></span>
      </template>
    </el-table-column>
    <el-table-column prop="signLotteryType" label="奖励类型" width="160" align="center">
      <template slot-scope="scope">
        <span v-if="scope.row.signLotteryType === 0"><el-tag type="warning">无额外奖励</el-tag></span>
        <span v-if="scope.row.signLotteryType === 1"><el-tag type="primary">免费抽奖</el-tag></span>
        <span v-if="scope.row.signLotteryType === 2"><el-tag type="success">奖励翻倍</el-tag></span>
      </template>
    </el-table-column>
    <el-table-column prop="signShareIsFixed" label="分享内容" width="160" align="center">
      <template slot-scope="scope">
        <span v-if="scope.row.signShareIsFixed === 0"><el-tag type="success">随机内容</el-tag></span>
        <span v-if="scope.row.signShareIsFixed === 1"><el-tag type="primary">固定内容</el-tag></span>
      </template>
    </el-table-column>
    <el-table-column prop="signShareArticleTitle" label="固定内容" width="160" align="center">
      <template slot-scope="scope">
        <span v-if="scope.row.signShareIsFixed === 0"><el-tag type="warning">无固定内容</el-tag></span>
        <span v-else><el-tag type="primary">{{scope.row.signShareArticleTitle}}</el-tag></span>
      </template>
    </el-table-column>
    <el-table-column prop="signLotteryRuleId" label="抽奖ID" width="280" align="center"/>
    <el-table-column fixed="right" label="操作" width="240" align="center">
      <template slot-scope="scope">
        <el-button type="primary" size="mini" @click="handleOpenEditPanel(scope)">编辑</el-button>
        <el-button type="danger" size="mini"  @click="handleDeleteData(scope)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
    <!-- 分页器 -->
    <el-pagination
      layout="total, sizes, prev, pager, next, jumper"
      :current-page="form.pageNum"
      :page-size="form.pageSize"
      :total="form.total"
      :page-sizes="[12, 50, 100, 200]"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange">
    </el-pagination>
  </div>
</template>

<script>
  // 组件引入
  // 方法工具引入
  import { PermissionsToDetectFormUser } from '@/utils/PermissionsDetect';
  import { getPermission } from '@/utils/UserCookies';
  // 接口引入
  import { loadCmsSignInList } from "@/api/operation";
  export default {
    name: "signIn",
    //import引入的组件需要注入到对象中才能使用
    components: {},
    data() {
      return {
        pageData:{
          loading: false
        },// 页面配置数据
        form:{
          pageNum: 1,// 表单--页码
          pageSize: 12,// 表单--页面
          total: 0,// 表单--总量
          selection: [],// 多选的内容
        },// 页面表单
        formRules: {},// 表单验证
        responseData: {
          tableList: []
        },// 接口响应数据
      }
    },
    //监听属性 类似于data概念
    computed: {},
    //监控data中的数据变化
    watch: {},
    //方法集合
    methods:{
      // 事件函数
      handlePageInit(){
        this.pageData.loading = true;// 创建加载窗口
        this.loadCmsSignInList();// 读取路由角色列表
      },// 页面初始化事件
      handleCurrentChange(val){
        this.form.pageNum = val;// 更换页码
        this.handlePageInit();// 进行数据加载
      },// 页码切换事件
      handleSizeChange(val){
        this.form.pageSize = val;// 更换页面大小
        this.handlePageInit();// 进行数据加载
      },// 页面size切换事件
      handleTableSelection(val){
        let list = [];// 初始化多选数组
        for (let i=0; i<val.length; i++){
          list.push(val[i].signId);
        }// 遍历多选的列表，将ID拼入数组中
        this.form.selection = list;// 进行多选值的切换
      },// 表格多选事件
      handleOpenEditPanel(scope){
        // 判断当前登录用户所拥有的的操作权限
        if (PermissionsToDetectFormUser(getPermission(), "270003")){
          // 获取勋章修改页数据
          this.$message.info('该功能暂未开放，请联系管理员');
        } else {
          // 当前权限不足，不执行操作，给与相应提示
          this.$message.warning('您的权限不足，无法使用此功能，请联系管理员');
        }
      },// 编辑按钮点击事件
      handleDeleteData(scope){
        // 判断当前登录用户所拥有的的操作权限
        if (PermissionsToDetectFormUser(getPermission(), "270002")){
          // 获取勋章修改页数据
          this.$message.info('该功能暂未开放，请联系管理员');
        } else {
          // 当前权限不足，不执行操作，给与相应提示
          this.$message.warning('您的权限不足，无法使用此功能，请联系管理员');
        }
      },// 删除按钮点击事件
      // 接口
      loadCmsSignInList(){
        loadCmsSignInList(this.form).then(response => {
          if (response.code === "200"){
            this.pageData.loading = false;
            this.responseData.tableList = response.data.list;
            this.form.total = response.data.total;
          } else {
            this.$message.warning(response.message);
          }
        }).catch( error =>{
          console.log(error);
          this.$message.error(error);
        })
      },// 获取数据列表
    },
    //生命周期 - 创建完成（可以访问当前this实例）
    created: function () {
      let _this = this;
      setTimeout(function () {
        _this.handlePageInit();
      }, 800);
    },
    //生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {},
    beforeCreate() {}, //生命周期 - 创建之前
    beforeMount() {}, //生命周期 - 挂载之前
    beforeUpdate() {}, //生命周期 - 更新之前
    updated() {}, //生命周期 - 更新之后
    beforeDestroy() {}, //生命周期 - 销毁之前
    destroyed() {}, //生命周期 - 销毁完成
    activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
  };
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
</style>
